@extends('admin.layouts.app')

@section('right-content')

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新增公告</legend>
    </fieldset>

    <form class="layui-form" action="" style="margin-right: 60%">
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" lay-verify="required" name="start_time" id="start_time" placeholder="请输入开始时间" readonly="">
            </div>
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" lay-verify="required" name="over_time" id="over_time" placeholder="请输入结束时间" readonly="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公告标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" value="" lay-verify="required" autocomplete="off" placeholder="请输入公告标题" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">公告内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" lay-verify="required" class="layui-textarea" name="content"></textarea>
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="enable" value="1" title="上线" checked>
                <input type="radio" name="enable" value="0" title="下线">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('ads.store') }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
   layui.use(['form', 'laydate'], function(){
       var form = layui.form, laydate = layui.laydate;
       // var start = {
       //      elem: '#start_time',
       //      type: 'datetime',
       //      format: 'yyyy-MM-dd HH:mm:ss',
       //      calendar: true,
       //      done: function(value, date) {
       //          end.min = value;
       //      },
       // };
       // var end = {
       //      elem: '#over_time',
       //      type: 'datetime',
       //      format: 'yyyy-MM-dd HH:mm:ss',
       //      calendar: true,
       //      done: function(value, date) {
       //          start.max = value;
       //      }
       // };
       // laydate.render(start);
       // laydate.render(end);

       // $('#start_time').on('focus', function(){
       //      laydate.render(start);
       // });
       // $('#over_time').on('focus', function(){
       //      laydate.render(end);
       // });


       var start = laydate.render({
            elem: '#start_time',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            calendar: true,
            done: function(value, date, endDate) {
                end.config.min = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                }
            }
       });

       var end = laydate.render({
            elem: '#over_time',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            calendar: true,
            done: function(value, date, endDate) {
                start.config.max = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                }
            }
       });

        form.on('submit(sub)', function(data){
            var url = $(this).attr('data-url');
            commonAjaxSubmit(url, 'POST');
        })
    });
</script>
@endsection

